package com.mofeng.myshop.domain.dto;

import com.mofeng.myshop.domain.dto.base.BaseDto;
import com.mofeng.myshop.domain.po.OrderFrom;
import com.mofeng.myshop.until.MyUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class OrderFromDto extends BaseDto {

    @Schema(description = "订单Id列表")
    private List<Long> orderFromList;

    @Schema(description = "订单状态 0 暂存购物车 1 交易失败 2 交易完成 3 等待发货 4等待签收")
    private String state;

    @Schema(description = "金额")
    private String money;

    @Schema(description= "数量")
    private Integer count;

    @Schema(description= "质量")
    private Integer multiplier;

    @Schema(description= "等级")
    private Integer level;

    @Schema(description= "是否是蓝图 0 没有 1 有")
    private Boolean isBluePic;

    @Schema(description = "收货地址")
    private String addressId;

    @Schema(description = "其他信息")
    private String otherMsg;

    @Schema(description = "商品信息，用JSON存(当商品删除时，会将商品信息存进来)")
    private String commodityMsg;

    @Schema(description = "商品id")
    private String commodityId;

    @Schema(description = "虚拟删除状态， 0 存在  1删除")
    private String delete;

    @Schema(description = "付款用户ID")
    private Long buyUserId;

    @Schema(description = "收货 用户ID")
    private Long toUserId;

    public OrderFrom toEntity() {
        OrderFrom orderFrom = new OrderFrom();
        toBaseEntity(orderFrom);
        if (this.state != null) {
            orderFrom.setState(this.state);
        }
        if (this.money != null) {
            orderFrom.setMoney(this.money);
        }
        if (this.count != null) {
            orderFrom.setCount(this.count);
        }
        if (this.multiplier != null) {
            orderFrom.setMultiplier(this.multiplier);
        }
        if (this.level != null) {
            orderFrom.setLevel(this.level);
        }
        if (this.isBluePic != null) {
            orderFrom.setIsBluePic(this.isBluePic?"1":"0");
        }
        if (this.addressId != null) {
            orderFrom.setAddressId(MyUtil.NumberUtil.asLong(this.addressId));
        }
        if (this.otherMsg != null) {
            orderFrom.setOtherMsg(this.otherMsg);
        }
        if (this.commodityMsg != null) {
            orderFrom.setErrorMsg(this.commodityMsg);
        }
        if (this.commodityId != null) {
            orderFrom.setCommodityId(MyUtil.NumberUtil.asLong(this.commodityId));
        }
        if (this.delete != null) {
            orderFrom.setDelete(this.delete);
        }
        if (this.buyUserId != null) {
            orderFrom.setBuyUserId(this.buyUserId);
        }
        if (this.toUserId != null) {
            orderFrom.setToUserId(this.toUserId);
        }
        return orderFrom;
    }
}
